package cn.iocoder.yudao.module.biobee.controller.admin.plot;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.biobee.controller.admin.plot.vo.PlotSubmitTaskReqVO;
import cn.iocoder.yudao.module.biobee.controller.admin.plot.vo.PlotUploadFileReqVO;
import cn.iocoder.yudao.module.biobee.service.plot.PlotService;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 绘图工具")
@RestController
@RequestMapping("/biobee/plot")
@Validated
@Slf4j
public class PlotController {

    @Resource
    private PlotService plotService;

    @RequestMapping("/submit-task")
    public CommonResult<Boolean> submitTask(@Valid @RequestBody PlotSubmitTaskReqVO plotSubmitTaskReqVO) throws IOException {
        plotService.submitTask(plotSubmitTaskReqVO);
        return success(true);
    }

    @RequestMapping("/upload-file")
    public CommonResult<Boolean> uploadFile(PlotUploadFileReqVO plotSubmitTaskReqVO) throws IOException {
        plotService.uploadFile(plotSubmitTaskReqVO);
        return success(true);
    }

    @GetMapping("/download-result")
    public void downloadFile(
            HttpServletResponse response,
            @RequestParam("projectId") String projectId,
            @RequestParam("taskId") String taskId,
            @RequestParam("fileName") String fileName // 新增的文件名参数
    ) throws IOException {
        plotService.downloadResult(response, projectId, taskId, fileName);
    }

    @GetMapping("/download-example")
    public void downloadExample(
            HttpServletResponse response,
            @RequestParam("projectType") String projectType,
            @RequestParam("taskType") String taskType,
            @RequestParam("fileName") String fileName
    ) throws IOException {
        plotService.downloadExample(response, projectType, taskType, fileName);
    }


}
